import { defineStore } from "pinia";
import axios from "axios";
import { nanoid } from "nanoid";

export const useloveTalkStore = defineStore("loveTalk", {
  actions: {
    async getATalk() {
      let {
        data: {
          data: { content },
        },
      } = await axios.get("https://api.xygeng.cn/one");
      //把请求回来的对象包装成一个对象

      let obj = { id: nanoid(), content };
      this.talkList.unshift(obj);
    },
  },
  state() {
    return {
      talkList: JSON.parse(localStorage.getItem("talkList") as string) || [],
    };
  },
});
